n = 10
Map = [list(input()) for _ in range(n)]
cnt = 0

def dfs(x, y, vis):
    if x < 0 or x >= n or y < 0 or y >= n:
        return True
    if vis[x][y]:
        return False

    vis[x][y] = 1
    direction = Map[x][y]

    if direction == 'U':
        return dfs(x-1, y, vis)
    elif direction == 'D':
        return dfs(x+1, y, vis)
    elif direction == 'L':
        return dfs(x, y-1, vis)
    elif direction == 'R':
        return dfs(x, y+1, vis)

for i in range(n):
    for j in range(n):
        vis = [[0]*n for _ in range(n)]  # 每个起点单独创建标记数组
        if dfs(i, j, vis):
            cnt += 1

print(cnt)
